package com.hanamaki.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class FileUtil {

    static FileInputStream fileInputStream = null;
    static InputStreamReader inputStreamReader = null;

    /**
     * 读取文件中的 数据
     * @param filePath ：文件的路径
     * @return
     */
    public static Object[][] getFileContent(String filePath) {
        Object result[][] = null;
        try {
            File file = new File(filePath);
            fileInputStream= new FileInputStream(file);
            inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
            /* 我们在读取文件中数据的时候，要一行一行的来读取 */
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            /* 定义一个变量来保存 文件中的数据 */
            String rowContent = null;
            /* 定义一个集合 */
            List<Object[]> list = new ArrayList<>();
            while ((rowContent = bufferedReader.readLine()) != null) {
                Object[] split = rowContent.split(",");
                list.add(split);
            }
            result = new Object[list.size()][];
            for (int i = 0; i < list.size(); i++) {
                result[i] = list.get(i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
